package com.example.pagenavigation.slice;

import com.example.pagenavigation.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.Component;
import ohos.agp.components.Text;

public class MainAbilitySlice extends AbilitySlice {
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);
        // 获取文本组件对象
        Text text = (Text)findComponentById(ResourceTable.Id_text_main);
        // 设置单击监听器
        text.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                // 创建Intent对象
                Intent _intent = new Intent();
                // 创建Operation对象
                Operation operation = new Intent.OperationBuilder() // 创建Operation对象
                        .withDeviceId("")  // 目标设备，空字符串代表本设备
                        .withBundleName("com.example.pagenavigation") // 通过BundleName指定应用程序
                        .withAbilityName("com.example.pagenavigation.SecondAbility") // 通过Ability的全名称（包名+类名）指定启动的Ability
                        .build();
                // 设置Intent对象的operation属性
                _intent.setOperation(operation);
                // 启动Ability
                startAbility(_intent);
            }
        });

    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
